package com.foreveross.fetl.core.domain.freight.hbase;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.OneToMany;

import org.apache.commons.lang3.StringUtils;

import com.foreveross.fetl.common.domain.BaseHBaseEntity;
import com.foreveross.fetl.common.jpa.annontation.HBaseColumn;

@javax.persistence.Table(name="LP_FREIGHT_MONITOR")
public class FreightMonitor extends BaseHBaseEntity{

	private static final long serialVersionUID = 8701520123824964994L;
	/**
	 *  航班号 string
	 */
	@HBaseColumn(qualifier="flightNo",family="planeinfo")
	private String flightNo;
	/**
	 * 航班日期 string
	 */
	@HBaseColumn(qualifier="flightDate",family="planeinfo")
	private String flightDate;
	/**
	 * 抓取日期 string
	 */
	@HBaseColumn(qualifier="grabDate",family="planeinfo")
	private String grabDate;
	/**
	 * 
		抓取第几次 num
	 */
	@HBaseColumn(qualifier="grabNum",family="planeinfo")
	private Integer grabNum;
	/**
	 * 仓位数
	 */
	@HBaseColumn(qualifier="cabinNum",family="planeinfo")
	private Integer cabinNum;
	/**
	 * 子仓新增数（较上次） num
	 */
	@HBaseColumn(qualifier="cabinNumForAdd",family="planeinfo")
	private Integer cabinNumForAdd;
	/**
	 * 子仓减少数（较上次） num
	 */
	@HBaseColumn(qualifier="cabinNumForDel",family="planeinfo")
	private Integer cabinNumForDel;
	/**
	 * 最低价
	 */
	@HBaseColumn(qualifier="lowerPrice",family="planeinfo")
	private Double lowerPrice;
	/**
	 * 最高价
	 */
	@HBaseColumn(qualifier="heightPrice",family="planeinfo")
	private Double heightPrice;
	/**渠道*/
	@HBaseColumn(qualifier="grabChannel",family="planeinfo")
	private String grabChannel;
	/**渠道码（如南航：20005）*/
	@HBaseColumn(qualifier="grabChannelKey",family="planeinfo")
	private String grabChannelKey;
	
	/**起点（三字码）*/
	@HBaseColumn(qualifier="fromCity",family="planeinfo")
	private String fromCity;
	
	/**终点*/
	@HBaseColumn(qualifier="toCity",family="planeinfo")
	private String toCity;
	
	@HBaseColumn(qualifier="fromCityName",family="planeinfo")
	private String fromCityName;
	@HBaseColumn(qualifier="toCityName",family="planeinfo")
	private String toCityName;
	
	/**
	 * 仓位信息
	 */
	@OneToMany
	@HBaseColumn(qualifier="cabins",family="planeinfo")
	private Set<CabinEntity> cabins = new HashSet<CabinEntity>();
	
	public FreightMonitor(String flightNo, String flightDate, String grabDate,
			Integer grabNum, Integer cabinNum, Integer cabinNumForAdd,
			Integer cabinNumForDel, Double lowerPrice, Double heightPrice,
			String grabChannel, String grabChannelKey, String fromCity,
			String toCity, String fromCityName, String toCityName,
			Set<CabinEntity> cabins) {
		super();
		this.flightNo = flightNo;
		this.flightDate = flightDate;
		this.grabDate = grabDate;
		this.grabNum = grabNum;
		this.cabinNum = cabinNum;
		this.cabinNumForAdd = cabinNumForAdd;
		this.cabinNumForDel = cabinNumForDel;
		this.lowerPrice = lowerPrice;
		this.heightPrice = heightPrice;
		this.grabChannel = grabChannel;
		this.grabChannelKey = grabChannelKey;
		this.fromCity = fromCity;
		this.toCity = toCity;
		this.fromCityName = fromCityName;
		this.toCityName = toCityName;
		this.cabins = cabins;
	}

	public String getGrabChannelKey() {
		return grabChannelKey;
	}

	public void setGrabChannelKey(String grabChannelKey) {
		this.grabChannelKey = grabChannelKey;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		this.toCity = toCity;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

	public String getToCityName() {
		return toCityName;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}

	public Set<CabinEntity> getCabins() {
		return cabins;
	}

	public Integer getCabinNumForDel() {
		return cabinNumForDel;
	}

	public void setCabinNumForDel(Integer cabinNumForDel) {
		this.cabinNumForDel = cabinNumForDel;
	}

	public void setCabins(Set<CabinEntity> cabins) {
		this.cabins = cabins;
	}

	public String getFlightNo() {
		return flightNo;
	}

	public void setFlightNo(String flightNo) {
		this.flightNo = flightNo;
	}

	public String getFlightDate() {
		return flightDate;
	}

	public void setFlightDate(String flightDate) {
		this.flightDate = flightDate;
	}

	public String getGrabDate() {
		return grabDate;
	}

	public void setGrabDate(String grabDate) {
		this.grabDate = grabDate;
	}

	public Integer getGrabNum() {
		return grabNum;
	}

	public void setGrabNum(Integer grabNum) {
		this.grabNum = grabNum;
	}

	public Integer getCabinNum() {
		return cabinNum;
	}

	public void setCabinNum(Integer cabinNum) {
		this.cabinNum = cabinNum;
	}

	public Integer getCabinNumForAdd() {
		return cabinNumForAdd;
	}

	public void setCabinNumForAdd(Integer cabinNumForAdd) {
		this.cabinNumForAdd = cabinNumForAdd;
	}

	public Double getLowerPrice() {
		return lowerPrice;
	}

	public void setLowerPrice(Double lowerPrice) {
		this.lowerPrice = lowerPrice;
	}

	public Double getHeightPrice() {
		return heightPrice;
	}

	public void setHeightPrice(Double heightPrice) {
		this.heightPrice = heightPrice;
	}

	public String getGrabChannel() {
		return grabChannel;
	}

	public void setGrabChannel(String grabChannel) {
		this.grabChannel = grabChannel;
	}

	/**
	 * 渠道 所在地 目的地 航班号 航班日期 抓取日期 抓取时分
	 * 5  位 3字 码 3字  码 六    位 8位 	  8位	   4位
	 */
	@Override
	public String generateRowKey() {
		return new StringBuilder().append(grabChannelKey).append(fromCity)
				.append(toCity).append(StringUtils.leftPad(flightNo, 8, '0'))
				.append(flightDate.replace("-", "").substring(0, 8))
				.append(grabDate.substring(0, 8))
				.append(grabDate.substring(8, 12)).toString();
	}
	
}
